package demo2.assignment3;

import java.util.Map;

/**
 * @author Leon(赵亮)
 * @version 1.0.0
 * 10 Sep 2021
 * This is Faculty Member Adapter, Which user should use this adapter to convert UserInfo into Faculty Member so that
 * the new System will run well when connect with the old system.
 */
public class FacultyMemberAdapter {

    public FacultyMember adapter(UserInfo userInfo) {
        FacultyMember facultyMember = new FacultyMember();
        facultyMember.setIdentification(getIdentification(userInfo));
        facultyMember.setName(userInfo.getName());
        for (Map.Entry<String, String> next : userInfo.getUserTeles().entrySet()) {
            facultyMember.setContactTelephone(next.getValue());
            break;
        }
        return facultyMember;
    }

    private String getIdentification(UserInfo userInfo) {
        StringBuilder identification = new StringBuilder(userInfo.getNumber());
        for (int i = 4; i > userInfo.getId().length(); i--) {
            identification.append("0");
        }
        identification.append(userInfo.getId());
        return identification.toString();
    }
}
